<script setup>
import { onMounted, ref, onUnmounted, defineProps } from 'vue'

const props = defineProps({
  title: String
})
const isFixed = ref(false)
onMounted(() => {
  window.addEventListener('scroll', initHeight)
})
const initHeight = () => {
  let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
  isFixed.value = scrollTop > 152 ? true : false
}
onUnmounted(() => {
  // 第三个参数：true是捕获，false是冒泡
  window.removeEventListener('scroll', initHeight, false)
})
</script>

<template>
  <div class="nav-bar" :class="{ 'is_fixed': isFixed }">
    <div class="container">
      <div class="pro-title">
        {{ title }}
      </div>
      <div class="pro-param">
        <a href="javascript:;">概述</a><span>|</span>
        <a href="javascript:;">参数</a><span>|</span>
        <a href="javascript:;">用户评价</a>
        <slot name="buy">

        </slot>
      </div>
    </div>
  </div>
</template>

<style lang="scss">
@import '@/assets/config.scss';
@import '@/assets/mixin.scss';

.nav-bar {
  height: 70px;
  line-height: 70px;
  border: 1px solid $colorH;
  display: flex;
  background-color: $colorG;
  z-index: 10;

  &.is_fixed {
    position: fixed;
    top: 0;
    width: 100%;
    box-shadow: 0 5px 5px $colorE;
  }

  .container {
    @include flex();

    .pro-title {
      font-size: $colorH;
      color: $colorB;
      font-weight: bold;
      font-size: 18px;
    }

    .pro-param {
      font-size: $fontJ;
      color: $colorC;

      span {
        margin: 0 10px;
      }

      a {
        color: $colorC;
      }
    }
  }
}
</style>
